"""
需求：
    定义函数，在员工列表中查找所有部门是9001的员工
    定义函数，在员工列表中查找所有姓名是2个字的员工
使用Lambda表达式实现 结合生成器函数yield 使用
"""

class Employee:
    def __init__(self, eid, did, name, money):
        self.eid = eid  # 员工编号
        self.did = did  # 部门编号
        self.name = name
        self.money = money

    def __repr__(self):
        return f'Employee({self.eid}, {self.did}, {self.name}, {self.money})'



list_employees = [
    Employee(1001, 9002, "师父", 60000),
    Employee(1002, 9001, "孙悟空", 50000),
    Employee(1003, 9002, "猪八戒", 20000),
    Employee(1004, 9001, "沙僧", 30000),
    Employee(1005, 9001, "小白龙", 15000),
]



def find_emp(condition):
    for employee in list_employees:
        if condition(employee):
           yield employee


# for item in find_emp(lambda item : item.did == 9001):
#     print(item)

for item in find_emp(lambda item : len(item.name) == 2):
    print(item)